<template>
	<view>
		<view class="logins">
			<button class="btn" @click="getUserProfile">授权登录</button>
		</view>
	</view>
</template>

<script>
	import {
		getlogin
	} from "../utils/api"
	import {
		Base64
	} from '../../js_sdk/js-base64/base64.js'
	export default {
		data() {
			return {

			}
		},
		methods: {

			//获取头像
			getUserProfile() {
				let that = this
				uni.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						console.log(res);
						const appid = "wxd3190da40e0119d8"
						const secret = "8d3a04dcba1be8868f8cdafbeb9d29a5"
						const nickName = res.userInfo.nickName
						const avatarUrl = res.userInfo.avatarUrl
						uni.setStorageSync('logins', res.userInfo)
						uni.login({
							success(res1) {
								// 获取code
								if (res1.code) {
									console.log(res1);
									const code = res1.code
									// console.log(appid,secret,nickName,avatarUrl);
									getlogin({
										appid,
										secret,
										nickName,
										avatarUrl,
										code
									}).then((res) => {
										console.log(res);
										let Uaertoken = Base64.encode(res.data.data
											.user_Token + ':')
										console.log(Uaertoken, 12);
										console.log(res.data.data
											.user_Token);
										uni.setStorageSync("token", Uaertoken)
										uni.switchTab({
											url: "/pages/my/my"
										})
									})
								}

							}
						})

					}

				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.logins {
		width: 100%;

		.btn {
			width: 100px;
			height: 50px;
			margin: auto;
		}
	}
</style>
